package motor;

import java.awt.Color;
import java.awt.Graphics;

import utils.Vector2d;

public class ModuleLife
{
	float pvMax;
	float pv;
	
	public ModuleLife( float pvMax)
	{
		this.pvMax = pvMax;
		pv = pvMax;
	}
	
	public void damage(float degats)
	{
		pv -= degats;
		
		if( pv < 0 )
		{
			pv = 0;
		}
	}

	public boolean isDead()
	{
		if( pv != 0 )
			return false;
		return true;
	}
	
	public float getRapport()
	{
		return pv/pvMax;
	}

	public void draw(Graphics buffer_canvas, Vector2d pos, int size )
	{
		if( getRapport() > 0.75 )
			buffer_canvas.setColor( Color.green );
		else if( getRapport() > 0.50 )
			buffer_canvas.setColor( Color.yellow );
		else if( getRapport() > 0.50 )
			buffer_canvas.setColor( Color.orange );
		else
			buffer_canvas.setColor( Color.red );
		
		buffer_canvas.fillRect( (int)(pos.x-size-size/2) , (int)(pos.y-8 ) , (int)(size*3 * getRapport()) , 3 );
		
		buffer_canvas.setColor( Color.black );
		
		buffer_canvas.drawRect( (int)(pos.x-size-size/2) , (int)(pos.y-8 ) , (int)(size*3 ) , 3 );
	}
}
